﻿using System.Data.Common;
using System.Data.Entity;
using Abp.Zero.EntityFramework;
using MyCompanyName.AbpZeroTemplate.Authorization.Roles;
using MyCompanyName.AbpZeroTemplate.Authorization.Users;
using MyCompanyName.AbpZeroTemplate.MultiTenancy;
using MyCompanyName.AbpZeroTemplate.Storage;

namespace MyCompanyName.AbpZeroTemplate.EntityFramework
{
    public class AbpZeroTemplateDbContext : AbpZeroDbContext<Tenant, Role, User>
    {

        public virtual IDbSet<Prm.Admin.SystemDic> SystemDic { get; set; } 
       // public virtual IDbSet<Prm.Admin.DocLog> DocLog { get; set; }
        public virtual IDbSet<Prm.Inquiry.Inquiry> Inquiry { get; set; }
        public virtual IDbSet<Prm.Inquiry.InquiryReply> InquiryReply { get; set; }
        
        public virtual IDbSet<Daybooks.Daybook> Daybook { get; set; }
        public virtual IDbSet<Daybooks.DaybookItem> DaybookItem { get; set; }
        public virtual IDbSet<Gantt.TaskInfo> Tasks { get; set; }
        public virtual IDbSet<Gantt.Resource> Resources { get; set; }
        public virtual IDbSet<Gantt.Assignment> Assignments { get; set; }
        public virtual IDbSet<Gantt.Attachment> Attachments { get; set; }
        public virtual IDbSet<Gantt.Calendar> Calendars { get; set; }
        public virtual IDbSet<Gantt.CalendarDay> CalendarDays { get; set; }
        public virtual IDbSet<Gantt.Dependency> Dependencies { get; set; }
        public virtual IDbSet<Gantt.Option> Options { get; set; }
        public virtual IDbSet<Prm.Admin.MailRecord> MailRecord { get; set; }
        public virtual IDbSet<Prm.Admin.PlanTpl> PlanTpl { get; set; }
        public virtual IDbSet<Prm.Project.ProjectPhaseHistory> ProjectPhaseHistory { get; set; }
        public virtual IDbSet<Gantt.Schedule> Schedules { get; set; }
        public virtual IDbSet<Prm.Project.TopicAttachment> TopicAttachment { get; set; }
        public virtual IDbSet<Gantt.TaskSegment> TaskSegments { get; set; }
        //public virtual IDbSet<Prm.Project.Tag> Tag { get; set; }
        public virtual IDbSet<Prm.Project.ProjectProgress> ProjectProgress { get; set; }
        public virtual IDbSet<Prm.Project.ProjectInfo> ProjectInfo { get; set; }
        public virtual IDbSet<Prm.Project.ProjectTask> ProjectTask { get; set; }

        public virtual IDbSet<Prm.Project.ProjectTaskMember> ProjectTaskMember { get; set; }
        public virtual IDbSet<Prm.Project.ProjectTaskFollower> ProjectTaskFollower { get; set; }
        public virtual IDbSet<Prm.Project.ProjectTaskSubTask> ProjectTaskSubTask { get; set; }
        //public virtual IDbSet<Prm.Project.ProjectTaskRole> ProjectTaskRole { get; set; }

        public virtual IDbSet<Prm.Project.ProjectTaskAttachment> ProjectTaskAttachment { get; set; }
        public virtual IDbSet<Prm.Project.ProjectApplication> ProjectApplication { get; set; }
        public virtual IDbSet<Prm.Project.ProjectRoleInfo> ProjectRoleInfo { get; set; }
        public virtual IDbSet<Prm.Admin.Product> Product { get; set; }
        public virtual IDbSet<Prm.Admin.MailDefined> MailDefined { get; set; }
        public virtual IDbSet<Prm.Project.ProjectTeam> ProjectTeam { get; set; }
        public virtual IDbSet<Prm.Project.TeamComment> TeamComment { get; set; }
        public virtual IDbSet<Prm.Admin.DocumentType> DocumentType { get; set; }
        public virtual IDbSet<Prm.Project.ProjectDocmeut> ProjectDocmeut { get; set; }

        public virtual IDbSet<Prm.Project.ProjectDocmeutShare> ProjectDocmeutShare { get; set; } 
        public virtual IDbSet<Prm.Project.ProjectDocmeutShareMember> ProjectDocmeutShareMember { get; set; }

        public virtual IDbSet<Prm.Project.ProjectDocmeutVersion> ProjectDocmeutVersion { get; set; }
        public virtual IDbSet<Prm.Project.ProjectDocType> ProjectDocType { get; set; }
        public virtual IDbSet<Prm.Project.ProjectSummary> ProjectSummary { get; set; }
        public virtual IDbSet<Prm.Project.Topic> Topic { get; set; }
        public virtual IDbSet<Prm.Project.Reply> Reply { get; set; }
        public virtual IDbSet<Gantt.ChangeLog> ChangeLog { get; set; }
        public virtual IDbSet<Prm.Admin.PhaseInfo> PhaseInfo { get; set; }
        public virtual IDbSet<Prm.Admin.PhaseItem> PhaseItem { get; set; }
        public virtual IDbSet<Prm.Admin.Laboratory> Laboratory { get; set; }
        public virtual IDbSet<Prm.Admin.RdCenter> RdCenter { get; set; }

        public virtual IDbSet<Prm.Admin.Quan> Quan { get; set; }
        public virtual IDbSet<Prm.Project.ProjectQuan> ProjectQuan { get; set; }
        public virtual IDbSet<Prm.Project.TaskQuan> TaskQuan { get; set; }
        public virtual IDbSet<Prm.Admin.UserQuan> UserQuan { get; set; }

        public virtual IDbSet<Prm.Project.ProjectPhase> ProjectPhase { get; set; }
        public virtual IDbSet<Prm.Project.ProjectPhaseItem> ProjectPhaseItem { get; set; }

        public virtual IDbSet<Gantt.PushMessage> PushMessage { get; set; }
        public virtual IDbSet<Prm.Admin.Business> Business { get; set; }

        public virtual IDbSet<Prm.Authorization.ProjectRoleFunctionActions> ProjectRoleFunctionActions { get; set; }
        public virtual IDbSet<Prm.Authorization.ProjectRoleDocmentActions> ProjectRoleDocmentActions { get; set; }
        public virtual IDbSet<Prm.Authorization.SystemRoleFunctionActions> SystemRoleFunctionActions { get; set; }
        public virtual IDbSet<Prm.Authorization.SystemRoleDocmentActions> SystemRoleDocmentActions { get; set; }

        public virtual IDbSet<Prm.Project.ProjectFollower> ProjectFollowers { get; set; }

        public virtual IDbSet<Prm.Admin.OperationLog> OperationLog { get; set; }
        public virtual IDbSet<Prm.Synth.Synthesis> Synthesis { get; set; }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Gantt.Dependency>().HasRequired(x => x.FromTask).WithMany(x => x.Predecessors).HasForeignKey(x => x.FromIdRaw).WillCascadeOnDelete(false);
            modelBuilder.Entity<Gantt.Dependency>().HasRequired(x => x.ToTask).WithMany(x => x.Successors).HasForeignKey(x => x.ToIdRaw).WillCascadeOnDelete(false);
            base.OnModelCreating(modelBuilder);
        }



        /* Define an IDbSet for each entity of the application */

        public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }

        /* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
         * But it may cause problems when working Migrate.exe of EF. ABP works either way.         * 
         */
        public AbpZeroTemplateDbContext()
            : base("Default")
        {

        }

        /* This constructor is used by ABP to pass connection string defined in AbpZeroTemplateDataModule.PreInitialize.
         * Notice that, actually you will not directly create an instance of AbpZeroTemplateDbContext since ABP automatically handles it.
         */
        public AbpZeroTemplateDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {

        }

        /* This constructor is used in tests to pass a fake/mock connection.
         */
        public AbpZeroTemplateDbContext(DbConnection dbConnection)
            : base(dbConnection, true)
        {

        }
    }
}
